package com.kin.rich.output;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.kin.rich.dao.CommonDAO;
import com.kin.rich.dao.SearchdataDAO;
import com.kin.rich.pojo.Keyword;
import com.kin.rich.pojo.Searchdata;
import com.kin.rich.service.SpiderHelper;
import com.kin.rich.util.CalendarFunction;

public class CreateWebExcel {

	private SearchdataDAO srhDAO ;
	private CommonDAO commonDAO;
	private SpiderHelper helper;
	
	
	
	public void setHelper(SpiderHelper helper) {
		this.helper = helper;
	}

	public void setSrhDAO(SearchdataDAO srhDAO) {
		this.srhDAO = srhDAO;
	}

	public void setCommonDAO(CommonDAO commonDAO) {
		this.commonDAO = commonDAO;
	}

	public static CreateWebExcel getFromApplicationContext(ApplicationContext ctx) {
		return (CreateWebExcel) ctx.getBean("CreateWebExcel");
	}
	
	public void createWeekly(){
		//ApplicationContext appContext = new FileSystemXmlApplicationContext("/src/applicationContext.xml");
		//CreateHTML createHTML =  CreateHTML.getFromApplicationContext(appContext);
		/*createHTML("2010-09-06", "2010-09-12", 1, "中技系");
		createHTML("2010-09-06", "2010-09-12", 2, "法尔胜");
		createHTML("2010-09-06", "2010-09-12", 3, "星美");
		createHTML("2010-09-06", "2010-09-12", 4, "西南证券");
		createHTML("2010-09-06", "2010-09-12", 5, "双林股份");
		//createHTML("2010-08-23", "2010-08-29", 6, "招商基金");
		createHTML("2010-09-06", "2010-09-12", 7, "南方基金");
		createHTML("2010-09-06", "2010-09-12", 8, "华夏基金");
		createHTML("2010-09-06", "2010-09-12", 9, "东方集团");
		createHTML("2010-09-06", "2010-09-12", 10, "实达集团");*/
		//createHTML("2010-08-01", "2010-08-31", 11, "凯德置地");
		//createHTML("2010-01-01", "2010-09-08", 12, "好买基金");
		//createHTML("2010-07-01", "2010-09-09", 13, "QDII基金");
		//createHTML("2008-01-06", "2010-09-19", 14, "太化股份狄重阳2");
		this.createHTMLByWordId("2008-01-06", "2010-09-19", 35);
	}
	public static void main(String[] args) {
		ApplicationContext appContext = new FileSystemXmlApplicationContext("/src/applicationContext.xml");
		CreateWebExcel createHTML =  CreateWebExcel.getFromApplicationContext(appContext);
		createHTML.createWeekly();
		System.out.println("!!!!!!!!!!!!!");
		
		
		
		//createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 26);
		/*createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 25);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 21);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 22);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 23);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 24);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 20);
		createHTML.createHTMLByWordIdForHuang("2010-08-01", "2010-08-25", 4);*/
	}

	
	public void createHTML(String startDate,String endDate,int compId,String compName){
		try{
			List<Keyword> keywords = helper.getValidKeyword(compId);
			File file = new File("E:/ses/"+compName+"网页搜索监测.html");
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
	        PrintWriter pw = new PrintWriter(fos);
			pw.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" /></head><body><table width=95% cellspacing=1 border=1px>");
			pw.write("<tr align=center  style=\"HEIGHT: 38.25pt; mso-height-source: userset\" height=51><td width=100% colspan=7  style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow;HEIGHT: 38.25pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl71 height=51><FONT size=5 face=宋体><STRONG>"+compName+"舆情分析周报（"+startDate+"-"+endDate+"）</STRONG></FONT></TD></TR>");
			pw.write("<tr  style=\"HEIGHT: 13.5pt\" height=18 >"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: gray; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" height=18 ><STRONG><FONT size=2 face=宋体>序号</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=65><STRONG><FONT size=2 face=宋体>时间</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=50><STRONG><FONT size=2 face=宋体>关键词</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=79><STRONG><FONT size=2 face=宋体>媒体</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=299><STRONG><FONT size=2 face=宋体>标题</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=444><STRONG><FONT size=2 face=宋体>链接</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=38><STRONG><FONT size=2 face=宋体>性质</FONT></STRONG></td>"
					+"</tr>");
			int no = 1;
			for(int i=0;i<keywords.size();i++){
				
				Keyword keyword = keywords.get(i);System.out.println(keyword.getWordName());
				String hql = "from Searchdata where wordId="+keyword.getWordId()+" and (searchDate between '"+startDate+"' and '"+endDate+"') and dataCat!='10' and source='BaiduWeb' and dataIndexNo<=140 order by dataIndexNo";
				List<Searchdata> list = commonDAO.findByQuery(hql, 0, 0);
				for(int j = 0 ;j<list.size();j++){
					Searchdata data = list.get(j);
					pw.write("<TR style=\"HEIGHT: 13.5pt\" height=18>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 height=18 width=40 align=right><FONT size=2 face=宋体>"+no+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl66 width=65 align=right><FONT size=2 face=宋体>"+CalendarFunction.dateToString(data.getSearchDate())+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=50><FONT size=2 face=宋体>"+keyword.getWordName()+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=79><FONT size=2 face=宋体>"+data.getSource().replace("BaiduNews", "")+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=299><FONT size=2 face=宋体>"+data.getDataTitle()+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl67 width=444><SPAN style=\"FONT-SIZE: 9pt\"><FONT face=宋体><a href=\""+data.getLinkUrl()+"\">"+data.getLinkUrl()+"</a></FONT></SPAN></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=38><FONT size=2 face=宋体>&nbsp;</FONT></TD></TR>");

					no++;
				}
			}
			pw.write("<tr style=\"HEIGHT: 13.5pt; mso-height-source: userset ;\" height=18>"
					+"<td align=center style=\"BORDER-BOTTOM: black 0.5pt solid;BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow; WIDTH: 762pt; HEIGHT: 13.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl74 height=18 width=1015 colSpan=7><STRONG><FONT face=宋体>舆情分析</FONT></STRONG></td></tr>");
			pw.write("<tr style=\"HEIGHT: 13.5pt\" height=18><td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 762pt; HEIGHT: 73.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl77 height=98 rowSpan=3 width=1015 colSpan=7><FONT face=宋体><p>&nbsp;</p><p>&nbsp;</p></FONT></TD></tr>");
			
			pw.write( "</table></body></html>");
			pw.flush();
			fos.flush();
	               fos.close();
	               pw.close();
		}catch(Exception e){
			e.printStackTrace();

		}

	}

	public void createHTMLByWordId(String startDate,String endDate,int wordId){
		try{
			Keyword keyword = helper.getKeywordById(wordId);
			File file = new File("E:/ses/"+keyword.getWordName()+startDate+"--"+endDate+"百度网页.html");
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
	        PrintWriter pw = new PrintWriter(fos);
			pw.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" /></head><body><table width=95% cellspacing=1 border=1px>");
			pw.write("<tr align=center  style=\"HEIGHT: 38.25pt; mso-height-source: userset\" height=51><td width=100% colspan=7  style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow;HEIGHT: 38.25pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl71 height=51><FONT size=5 face=宋体><STRONG>"+keyword.getWordName()+"网页内容分析（"+startDate+"-"+endDate+"）</STRONG></FONT></TD></TR>");
			pw.write("<tr  style=\"HEIGHT: 13.5pt\" height=18 >"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: gray; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" height=18 ><STRONG><FONT size=2 face=宋体>序号</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=65><STRONG><FONT size=2 face=宋体>时间</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=50><STRONG><FONT size=2 face=宋体>关键词</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=79><STRONG><FONT size=2 face=宋体>媒体</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=299><STRONG><FONT size=2 face=宋体>标题</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=444><STRONG><FONT size=2 face=宋体>链接</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=38><STRONG><FONT size=2 face=宋体>百度索引</FONT></STRONG></td>"
					+"</tr>");
			int no = 1;
			//for(int i=0;i<keywords.size();i++){/
				//Keyword keyword = keywords.get(i);
				String hql = "from Searchdata where wordId="+keyword.getWordId()+" and dataCat!='10' and source='BaiduWeb'  order by dataId";
				List<Searchdata> list = commonDAO.findByQuery(hql, 0, 0);
				for(int j = 0 ;j<list.size();j++){
					Searchdata data = list.get(j);
					System.out.println(j+data.getSearchDate().toString()+data.getDataTitle()+data.getSource());
					pw.write("<TR style=\"HEIGHT: 13.5pt\" height=18>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 height=18 width=40 align=right><FONT size=2 face=宋体>"+no+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl66 width=65 align=right><FONT size=2 face=宋体>"+CalendarFunction.dateToString(data.getSearchDate())+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=50><FONT size=2 face=宋体>"+keyword.getWordName()+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=79><FONT size=2 face=宋体>"+data.getSource().replace("BaiduNews", "")+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=299><FONT size=2 face=宋体>"+data.getDataTitle()+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl67 width=444><SPAN style=\"FONT-SIZE: 9pt\"><FONT face=宋体><a href=\""+data.getLinkUrl()+"\">"+data.getLinkUrl()+"</a></FONT></SPAN></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=38><FONT size=2 face=宋体>第"+data.getDataIndexNo()+"位</FONT></TD></TR>");

					no++;
				}
			//}
			pw.write("<tr style=\"HEIGHT: 13.5pt; mso-height-source: userset ;\" height=18>"
					+"<td align=center style=\"BORDER-BOTTOM: black 0.5pt solid;BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow; WIDTH: 762pt; HEIGHT: 13.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl74 height=18 width=1015 colSpan=7><STRONG><FONT face=宋体>网页分析</FONT></STRONG></td></tr>");
			pw.write("<tr style=\"HEIGHT: 13.5pt\" height=18><td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 762pt; HEIGHT: 73.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl77 height=98 rowSpan=3 width=1015 colSpan=7><FONT face=宋体><p>&nbsp;</p><p>&nbsp;</p></FONT></TD></tr>");
			
			pw.write( "</table></body></html>");
			pw.flush();
			fos.flush();
	               fos.close();
	               pw.close();
		}catch(Exception e){
			e.printStackTrace();

		}

	}
	public void createHTMLByWordIdForHuang(String startDate,String endDate,int wordId){
		try{
			Keyword keyword = helper.getKeywordById(wordId);
			File file = new File("E:/ses/faersheng/"+keyword.getWordName()+startDate+"--"+endDate+".html");
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
	        PrintWriter pw = new PrintWriter(fos);
			pw.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" /></head><body><table width=95% cellspacing=1 border=1px>");
			pw.write("<tr align=center  style=\"HEIGHT: 38.25pt; mso-height-source: userset\" height=51><td width=100% colspan=8  style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow;HEIGHT: 38.25pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl71 height=51><FONT size=5 face=宋体><STRONG>"+keyword.getWordName()+"舆情分析（"+startDate+"-"+endDate+"）</STRONG></FONT></TD></TR>");
			pw.write("<tr  style=\"HEIGHT: 13.5pt\" height=18 >"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: gray; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" height=18 ><STRONG><FONT size=2 face=宋体>企业名称</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=65><STRONG><FONT size=2 face=宋体>报道标题</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=50><STRONG><FONT size=2 face=宋体>报道时间</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=79><STRONG><FONT size=2 face=宋体>报道媒体</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=299><STRONG><FONT size=2 face=宋体>市场活动</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=444><STRONG><FONT size=2 face=宋体>知名产品子品牌</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=38><STRONG><FONT size=2 face=宋体>市场评价（占有率、荣誉称号、媒体评价）</FONT></STRONG></td>"
					+"<td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: gray; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl68 width=38><STRONG><FONT size=2 face=宋体>公益活动</FONT></STRONG></td>"
					
					+"</tr>");
			int no = 1;
			//for(int i=0;i<keywords.size();i++){/
				//Keyword keyword = keywords.get(i);
				String hql = "from Searchdata where wordId="+keyword.getWordId()+" and (searchDate between '"+startDate+"' and '"+endDate+"') and dataCat!='10' and source='BaiduWeb'  order by searchDate";
				List<Searchdata> list = commonDAO.findByQuery(hql, 0, 0);
				for(int j = 0 ;j<list.size();j++){
					Searchdata data = list.get(j);
					//System.out.println(j+data.getSearchDate().toString()+data.getDataTitle()+data.getSource());
					pw.write("<TR style=\"HEIGHT: 13.5pt;align:left;\" height=18>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 30pt; HEIGHT: 13.5pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 height=18 width=40 align=right><FONT size=2 face=宋体>"+keyword.getWordName()+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 49pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl66 width=65 align=left><FONT size=2 face=宋体><a href=\""+data.getLinkUrl()+"\">"+data.getDataTitle()+"</a></FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 38pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=50><FONT size=2 face=宋体>"+CalendarFunction.dateToString(data.getSearchDate())+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 59pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=79><FONT size=2 face=宋体>"+data.getSource().replace("BaiduNews", "")+"</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 224pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=299><FONT size=2 face=宋体>&nbsp;</FONT></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl67 width=444><SPAN style=\"FONT-SIZE: 9pt\"><FONT face=宋体>&nbsp;</FONT></SPAN></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 333pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl67 width=444><SPAN style=\"FONT-SIZE: 9pt\"><FONT face=宋体>&nbsp;</FONT></SPAN></TD>"+
"<TD style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black; BACKGROUND-COLOR: transparent; WIDTH: 29pt; BORDER-TOP: black; BORDER-RIGHT: black 0.5pt solid\" class=xl65 width=38><FONT size=2 face=宋体>&nbsp;</FONT></TD></TR>");

					no++;
				}
			//}
			pw.write("<tr style=\"HEIGHT: 13.5pt; mso-height-source: userset ;\" height=18>"
					+"<td align=center style=\"BORDER-BOTTOM: black 0.5pt solid;BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: yellow; WIDTH: 762pt; HEIGHT: 13.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl74 height=18 width=1015 colSpan=8><STRONG><FONT face=宋体>舆情分析</FONT></STRONG></td></tr>");
			pw.write("<tr style=\"HEIGHT: 13.5pt\" height=18><td style=\"BORDER-BOTTOM: black 0.5pt solid; BORDER-LEFT: black 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 762pt; HEIGHT: 73.5pt; BORDER-TOP: black 0.5pt solid; BORDER-RIGHT: black 0.5pt solid\" class=xl77 height=98 rowSpan=3 width=1015 colSpan=8><FONT face=宋体><p>&nbsp;</p><p>&nbsp;</p></FONT></TD></tr>");
			
			pw.write( "</table></body></html>");
			pw.flush();
			fos.flush();
	               fos.close();
	               pw.close();
		}catch(Exception e){
			e.printStackTrace();

		}

	}
}
